/*获取订单号*/
var orderiiid = sessionStorage.getItem("orderIId");
var pId = sessionStorage.getItem("pid");
var orderstatusqq="";//待审核 20
var login_accounts=""
getOrderDetai();
/*通过订单号获取订单详情*/
function getOrderDetai(){
    $("#datatable").html(" <thead>\n" +
        "                    <tr class=\"text-c\">\n" +
        "                        <th style=\"width: 300px;\">商品</th>\n" +
        "                        <th>发货仓</th>\n" +
        "                        <th>购买数量</th>\n" +
        "                        <th>发货数量</th>\n" +
        "                        <th>收货数量</th>\n" +
        "                        <th>可退数量</th>\n" +
        "                        <th>单价</th>\n" +
        "                        <th>满减券分摊</th>\n" +
        "                        <th>运费分摊</th>\n" +
        "                        <th>促销分摊</th>\n" +
        "                        <th>积分分摊</th>\n" +
        "                        <th>小计</th>\n" +
        "                    </tr>\n" +
        "                    </thead>\n" +
        "                    <tbody class=\"shun\">\n" +
        "                    </tbody>")
    $.ajax({
        type: "POST",
        url:root.orderInter.order_QyOrderDetails ,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        contentType: "application/json",
        data: JSON.stringify({
            "id":pId,
            order_id: orderiiid, // 订单编号
        }),
        success: function(result) {
            console.log(result.data)
            orderstatusqq =result.data.orderBase.order_status
            if(result.listOrderRefund !=null && result.listOrderRefund !='' ){
                $("#returnInfoBox").css({
                    display: "block"
                });
            }else {
                $("#returnInfoBox").css({
                    display: "none"
                });
            }
            for(var i = 0; i < result.data.listOrderVerifyRecord.length; i++) {
                if(result.data.listOrderVerifyRecord[i].account_type == 10 && result.data.listOrderVerifyRecord[i].verify_status == 0) {
                    $("#customerCheck").show();
                } else {
                    $("#customerCheck").hide();
                }
            }
            if(result.data.orderBase.anomal_check == 10 && result.data.orderBase.order_status == 20) {
                $("#customerServiceCheck").show();
            } else {
                $("#customerServiceCheck").hide();
            }
            if(result.data.orderExt != null && result.data.orderExt.platform==10 ){
                $("#alsi").hide();
            }else {
                $("#alsi").show();
            }
            if(result.data.orderExt != null && result.data.orderExt.platform==10|| result.data.orderBase.order_status==10||result.data.orderBase.order_status==20||result.data.orderBase.order_status==40||result.data.orderBase.order_status==50||result.data.orderBase.order_status==60||result.data.orderBase.order_status==70||result.data.orderBase.order_status==80||result.data.orderBase.order_status==90||result.data.orderBase.order_status==100||result.data.orderBase.order_status==110||result.data.orderBase.order_status==9){
                $("#assassin").hide();
            }
            //上门自提
            if(result.data.orderExt.sent_type==50){
                $("#selftakein").css({
                    display: "block"
                });
                $("#selftakeshop").css({
                    display: "block"
                });
                $("#receiverdetailaddress").css({
                    display: "block"
                });
                $("#selftakephone").css({
                    display: "block"
                });
                $("#wanna_edin").css({
                    display: "none"
                });
                $("#predixttime").css({
                    display: "none"
                });
            }else {
                $("#selftakein").css({
                    display: "none"
                });
                $("#selftakeshop").css({
                    display: "none"
                });
                $("#receiverdetailaddress").css({
                    display: "none"
                });
                $("#selftakephone").css({
                    display: "none"
                });
                $("#wanna_edin").css({
                    display: "block"
                });
                $("#predixttime").css({
                    display: "block"
                });
            }
            if (result.data.orderExt != null && result.data.orderExt.final_sent_type == 10  ) {
                $("#dexpress_company2").show();
                $("#eexpress_num").show();
                $("#cexpress_company").hide();
                $("#bdistributor-phone").hide();
                $("#adriver-phone").hide();
                $("#dexpress_company3").hide();
                $("#eexpress_num3").hide();
            }else if (result.data.orderExt != null && result.data.orderExt.final_sent_type == 20  ) {
                $("#dexpress_company3").show();
                $("#eexpress_num3").show();
                $("#cexpress_company").hide();
                $("#bdistributor-phone").hide();
                $("#adriver-phone").hide();
                $("#dexpress_company2").hide();
                $("#eexpress_num").hide();
            } else if (result.data.orderExt != null && result.data.orderExt.final_sent_type == 30  ) {
                $("#cexpress_company").show();
                $("#adriver-phone").show();
                $("#bdistributor-phone").hide();
                $("#dexpress_company2").hide();
                $("#eexpress_num").hide();
                $("#dexpress_company3").hide();
                $("#eexpress_num3").hide();
            }else if ( result.data.orderExt != null && result.data.orderExt.final_sent_type == 40 ) {
                $("#adriver-phone").show();
                $("#bdistributor-phone").show();
                $("#cexpress_company").hide();
                $("#dexpress_company2").hide();
                $("#eexpress_num").hide();
                $("#dexpress_company3").hide();
                $("#eexpress_num3").hide();
            }else if ( result.data.orderExt != null && result.data.orderExt.final_sent_type == 0 ) {
                $("#adriver-phone").hide();
                $("#bdistributor-phone").hide();
                $("#cexpress_company").hide();
                $("#dexpress_company2").hide();
                $("#eexpress_num").hide();
                $("#dexpress_company3").hide();
                $("#eexpress_num3").hide();
            }
            //驳回，跟进按钮显示
            if (result.data.is_rejected != null && result.data.is_rejected == 1 && result.data.orderRefund.refund_status==30 && result.data.orderCancleApply.deal_status==20) {
                $("#order_statue1").css({
                    display: "inline"
                });
                $("#order_statue2").css({
                    display: "none"
                });
                $("#returnGoods1").hide();
            } else {
                $("#order_statue1").css({
                    display: "none"
                });
                $("#order_statue2").css({
                    display: "none"
                });
                $("#returnGoods1").hide();
            }
            if(result.data.is_rejected != null && result.data.is_rejected == 0){
                if (result.data.orderCancleApply != null && result.data.orderCancleApply.deal_status == 10  ) {
                    $("#order_statue1").css({
                        display: "inline"
                    });
                    $("#order_statue2").css({
                        display: "inline"
                    });
                    $("#returnGoods1").hide();
                } else if (result.data.orderCancleApply != null && result.data.orderCancleApply.deal_status == 20  ) {
                    $("#order_statue1").css({
                        display: "inline"
                    });
                    $("#order_statue2").css({
                        display: "none"
                    });
                    $("#returnGoods1").show();
                } else if (result.data.orderCancleApply != null && result.data.orderCancleApply.deal_status == 30  ) {
                    $("#order_statue1").css({
                        display: "none"
                    });
                    $("#order_statue2").css({
                        display: "none"
                    });
                    $("#returnGoods1").hide();
                }
            }
            sessionStorage.setItem("orderDetail", JSON.stringify(result.data));
            renderOrderPage(result.data);
            if(result.data.listOrderRefund!=null){
                var listOrderRefunds=""
                $.each(result.data.listOrderRefund,function(k,v){
                    listOrderRefunds+='<tr><td class="col-2-1">退货单号：<span id="returnId"></span><a onclick="returnOrderInfo(\'退货单详情\',\'../afterSale/afterSaleService-returns.html\',\''+v.refund_id+'\',\''+v.order_id+'\')">'+v.refund_id+'</a></td><td class="col-2-1">申请时间：<span id="applytime"></span><span>'+v.created_at+'</span></td></tr>';
                })
                $("#returnTable").empty().append($(listOrderRefunds))
            }
            //将所有按钮隐藏
            $("#affirmMoney").siblings().css({
                display: "none"
            });
            /*确认认款按钮判断*/
            if((result.data.orderBase.paid_type == 1301 || result.data.orderBase.paid_type == 1401) && (result.data.orderBase.order_status == 9 || result.data.orderBase.order_status == 10)) {
                if(result.data.orderBase.customer_verify_status == 0){
                    $("#affirmMoney").css({
                        display: "none"
                    });
                }
                if(result.data.orderBase.customer_verify_status == 10){
                    $("#orderAnomalCheckStatus").css({
                        display: "none"
                    });
                    $("#affirmMoney").css({
                        display: "inline"
                    });
                }
            } else if(result.data.orderBase.paid_type == 1101 && result.data.orderBase.order_status == 70) {
                if(result.data.listOrderRemark.length == 0) {
                    $("#comfirmMoneyRemark").val("");
                    $("#affirmMoney").css({
                        display:"inline"
                    })
                } else {
                    for(var i=0;i<result.data.listOrderRemark.length;i++){
                        if(result.data.listOrderRemark[i].operate_type == 10){
                            $("#affirmMoney").css({
                                display:"inline"
                            })
                            $("#comfirmMoneyRemark").html(result.data.listOrderRemark[i].remark);//确认认款备注
                        }else {
                            $("#comfirmMoneyRemark").val("");
                            $("#affirmMoney").css({
                                display: "inline"
                            });
                        }
                    }
                }
            }
            switch(result.data.orderBase.order_status) {
                case 9:
                    /*待审核*/
                    $("#detailCancel").css({
                        display: "inline"
                    });
                    break;
                case 10:
                    /*待付款*/
                    $("#detailCancel").css({
                        display: "inline"
                    });
                    break;
                /*订单状态*/
                case 20:
                    /*待审核*/
                    $("#detailCancel").css({
                        display: "inline"
                    });
                    $("#affirmMoney").css({
                        display: "none"
                    });
                    $("#orderSureStatus").css({
                        display: "none"
                    });
                    break;
                case 30:
                    /*待配货*/
                    $("#affirmMoney").css({
                        display: "none"
                    });
                    $(".updataBtn").css({
                        display: "inline"
                    });
                    $("#detailCancel").css({
                        display: "inline"
                    });
                    break;
                case 40:
                    /*待出库*/
                    $("#affirmMoney").css({
                        display: "none"
                    });
                    $("#detailCancel").css({
                        display: "none"
                    });
                    break;
                case 50:
                    /*待发货*/
                    $("#affirmMoney").css({
                        display: "none"
                    });
                    $("#detailCancel").css({
                        display: "none"
                    });
                    break;
                case 60:
                    /*待收货*/
                    $("#affirmMoney").css({
                        display: "none"
                    });
                    if(result.data.is_rejected != 1){
                        $("#clientRejection").css({
                            display: "inline"
                        });
                    }
                    break;
                case 70:
                    /*已收货，待结算*/
                    if (result.data.is_show==true){
                        $("#maintain").css({
                            display: "inline"
                        });
                        $("#returnGoods").css({
                            display: "inline"
                        });
                    }
                    $("#returnInfoBox").css({
                        display: "block"
                    });
                    break;
                case 80:
                    /*订单成功*/
                    $("#affirmMoney").css({
                        display: "none"
                    });


                    if (result.data.is_show==true){
                        $("#maintain").css({
                            display: "inline"
                        });
                        $("#returnGoods").css({
                            display: "inline"
                        });
                    }
                    $("#returnInfoBox").css({
                        display: "block"
                    });
                    break;
                case 90:
                    /*交易完成*/
                    $("#affirmMoney").css({
                        display: "none"
                    });
                    if (result.data.is_show==true){
                        $("#maintain").css({
                            display: "inline"
                        });
                        $("#returnGoods").css({
                            display: "inline"
                        })
                    }
                    $("#returnInfoBox").css({
                        display: "block"
                    });
                    break;
                case 100:
                    /*已取消*/

                    $("#affirmMoney").css({
                        display: "none"
                    });
                    $("#orderSureStatus").css({
                        display: "none"
                    });
                    $("#customerCheck").hide();
                    $("#customerServiceCheck").hide();

                    $("#buyAgain").css({
                        display: "inline"
                    });
                    $("#cancleReason").css({
                        display: "inline"
                    });
                    if(result.data.orderCancle.cancel_role == 10) {
                        $("#cancleReason").html("客户主动取消");
                    } else if(result.data.orderCancle.cancel_role == 20) {
                        $("#cancleReason").html("客服取消");
                    } else if(result.data.orderCancle.cancel_role == 30) {
                        $("#cancleReason").html("超时未支付取消");
                    }
                    $(".cancleBox").css({
                        display: "inline"
                    });
                    $("#returnInfoBox").css({
                        display: "block"
                    });
                    break;
                case 110:
                    /*交易关闭*/

                    $("#returnReason").css({
                        display: "inline"
                    });
                    $("#affirmMoney").css({
                        display: "none"
                    });
                    $("#returnInfoBox").css({
                        display: "block"
                    });
                    $(".closeBox").css({
                        display: "block"
                    });
                    break;
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
        }
    });
}
/*转换状态函数*/
function changeOrderState(orderState) {
    switch(orderState) {
        /*订单状态*/
        case 9:
            return "待付款";
            break;
        case 10:
            return "待付款";
            break;
        case 20:
            return "待审核";
            break;
        case 30:
            return "待配货";
            break;
        case 40:
            return "待出库";
            break;
        case 50:
            return "待发货";
            break;
        case 60:
            return "待收货";
            break;
        case 70:
            return "已收货，待结算";
            break;
        case 80:
            return "订单成功";
            break;
        case 90:
            return "交易完成";
            break;
        case 100:
            return "已取消";
            break;
        case 110:
            return "交易关闭";
            break;
    }
}
function calculate(listAddressReceiver,type) {
    var math=""
    var phone=""
    var he=""
    var size=listAddressReceiver.length
    if (listAddressReceiver.length==0){
        return "";
    }
    for (i=0;i<size;i++){
        if (i<size-1){
            math+=listAddressReceiver[i].receiver_name+" ;"
            phone+=listAddressReceiver[i].mobile+" ; "
            if (i%2!=0){
                he+=listAddressReceiver[i].receiver_name+listAddressReceiver[i].mobile+" ; <br/> "
            }else{
                he+=listAddressReceiver[i].receiver_name+listAddressReceiver[i].mobile+" ;  "
            }
        }else {
            math+=listAddressReceiver[i].receiver_name
            phone+=listAddressReceiver[i].mobile
            if (i%2!=0){
                he+=listAddressReceiver[i].receiver_name+listAddressReceiver[i].mobile+"  <br/> "
            }else{
                he+=listAddressReceiver[i].receiver_name+listAddressReceiver[i].mobile+"   "
            }
        }
    }
    if (type==1){
        return math
    }else if (type==2){
        return phone
    }
    else if (type==3){
        return he
    }
}

function changePayTypeState(payTypeState) {
    switch(payTypeState) {
        /*支付方式*/
        case 1001:
            return "在线支付";
            break;
        case 1002:
            return "支付宝支付";
            break;
        case 1003:
            return "微信支付";
            break;
        case 1101:
            return "货到付款";
            break;
        case 1102:
            return "货到付款-现金";
            break;
        case 1103:
            return "货到付款-pos机";
            break;
        case 1201:
            return "账期支付";
            break;
        case 1301:
            return "银行转账";
            break;
        case 1401:
            return "银行汇票";
            break;
        case 1701:
            return "门店付款";
            break;
    }
}
function changeDeliveryMethodType(DeliveryMethodType) {
    switch(DeliveryMethodType) {
        /*配送方式*/
        case 10:
            return "鑫方盛物流";
            break;
        case 20:
            return "店内自提";
            break;
    }
}

function changeCopies(is_required,file_copies,original_file) {
    var val
    if (is_required==20&&original_file==20){
        val='不需要资质文件'
        return val
    }
    if (is_required==10){
        val='需要&nbsp;&nbsp;&nbsp;&nbsp;'
    }else if (is_required==20){
        val='不需要&nbsp;&nbsp;&nbsp;&nbsp;'
    }
    val+=file_copies+'份&nbsp;&nbsp;&nbsp;&nbsp;'
    if (original_file==10){
        val+='资质原件'
    }else if (original_file==20){
        val+='非资质原件'
    }
    return val;
}


function changeInvoiceType(invoiceType) {
    switch(invoiceType) {
        /*发票类型*/
        case 10:
            return "增值税";
            break;
        case 20:
            return "普税";
            break;
    }
}

function changeCancleReason(cancleReason) {
    switch(cancleReason) {
        /*取消原因*/
        case 10:
            return "订购错误";
            break;
        case 11:
            return "价格高";
            break;
        case 12:
            return "无法满足到货时效";
            break;
        case 13:
            return "支付问题";
            break;
        case 14:
            return "重复下单";
            break;
        case 15:
            return "暂时不需要";
            break;
        case 16:
            return "订单信息有误";
            break;
        case 17:
            return "无货";
            break;
        case 18:
            return "其他";
            break;
        case 110:
            return "公司产品原因";
            break;
        case 101:
            return "客户原因";
            break;
    }
}
function changeCloseReason(closeReason) {
    switch(closeReason) {
        /*关闭原因*/
        case 10:
            return "商品质量问题";
            break;
        case 20:
            return "大小/型号与商品描述不符";
            break;
        case 30:
            return "颜色/图案与商品描述不符";
            break;
        case 40:
            return "功能/效果与商品描述不符";
            break;
        case 50:
            return "商城发错货";
            break;
        case 60:
            return "少件/漏件";
            break;
        case 70:
            return "多买/买错不想要了";
            break;
        case 80:
            return "到货物流破损";
            break;
        case 90:
            return "发票问题";
            break;
        case 100:
            return "未按约定时间发货";
            break;
        case 110:
            return "其他原因";
            break;
    }
}

/*渲染页面*/
/*头部按钮*/

function affirmMoney() {
    /*确认认款*/
    layer_show("确认收款", "affirmMoneyAlert.html", "600", "300");
}
/*跳转拒收页面*/
function clientRejection(title, url) {
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}
var isIngReturn = false;
function returnGoods(title) {
    if(isIngReturn){
        // layer.msg('请求已提交，请勿重复点击！');
        return false;
    }
    isIngReturn = true;
    getOrderDetai();
    setTimeout(function () {
        var orderDetail = JSON.parse(sessionStorage.getItem("orderDetail"));
        var orderState = orderDetail.orderBase.order_status;
        if(orderState == "70") {
            var url = "orderSuccess_refund.html";
        } else if(orderState == "80") {
            var url = "orderSuccess_refund.html";
        }
        else if(orderState == "90") {
            var url = "orderSuccess_refund.html";
        }
        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
    },200)
}

function detailCancel() {
    layer_show("取消订单", "cancleAlert.html", "600", "300");
}

function buyAgain() {
    window.location.href = "../replaceOrder/replace-order-01.html";
}
/*datatable*/
var dataSource = new Array();
//table的数据源
var table; //table对象
dataSource = [];

function renderOrderPage(data) {
    console.log(data)
    /*商品总金额计算*/
    var goodsAmount = 0;
    for(var i = 0; i < data.listOrderItems.length; i++) {
        goodsAmount += Number(data.listOrderItems[i].sale_price) * Number(data.listOrderItems[i].buyyer_count);
    }
    $("#goodsAmount").html(goodsAmount.toFixed(2));
    $("#fare").html(data.orderBase.shipping_fee);
    $("#orderAmount").html((goodsAmount + data.orderBase.shipping_fee).toFixed(2));
    /*转换状态*/
    var order_status = changeOrderState(data.orderBase.order_status);
    $("#orderState").html(order_status);
if(data.orderRefund!=null){

    if(data.orderRefund.customer_refund_reason!=0){
        $("#cancle_reason").html(data.orderRefund.customer_refund_reason);
        if(data.orderRefund.customer_refund_reason ==10){
            $("#cancle_reason").html('客户订购错误/计划有变');
        }else if(data.orderRefund.customer_refund_reason ==11){
            $("#cancle_reason").html('价格高');
        }else if(data.orderRefund.customer_refund_reason ==12){
            $("#cancle_reason").html('无法满足到货时效');
        }else if(data.orderRefund.customer_refund_reason ==13){
            $("#cancle_reason").html('支付问题');
        }else if(data.orderRefund.customer_refund_reason ==14){
            $("#cancle_reason").html('重复下单');
        }else if(data.orderRefund.customer_refund_reason ==15){
            $("#cancle_reason").html('暂时不需要了');
        }else if(data.orderRefund.customer_refund_reason ==16){
            $("#cancle_reason").html('订单信息有误');
        }else if(data.orderRefund.customer_refund_reason ==17){
            $("#cancle_reason").html('无货');
        }else if(data.orderRefund.customer_refund_reason ==18){
            $("#cancle_reason").html('其他');
        }else if(data.orderRefund.customer_refund_reason ==19){
            $("#cancle_reason").html('商品质量问题');
        }else if(data.orderRefund.customer_refund_reason ==20){
            $("#cancle_reason").html('价格错误');
        }else if(data.orderRefund.customer_refund_reason ==30){
            $("#cancle_reason").html('颜色/图案与商品描述不符');
        }else {
            $("#cancle_reason").html("");
        }
        //按钮展示
        if(data.orderCancleApply.deal_status==10&&data.orderCancleApply.cancel_apply_type==20){
            $("#order_statue1").html("<div class=\"btn radius  size-S ml-10\" onclick='dealmodal("+data.orderCancleApply.id+",\"" + data.orderCancleApply.order_id + "\")'><span class=\"list\" id='"+data.orderCancleApply.id+"' >驳回</span></div>")
            $("#order_statue2").html(" <div class=\"btn radius  size-S ml-10\" onclick='adopt("+data.orderCancleApply.id+",\"" + data.orderCancleApply.order_id + "\","+data.orderCancleApply.cancle_reason+")'><span class=\"list\" id='"+data.orderCancleApply.id+"' >通过</span></div>")
        }else {
            $("#order_statue1").html("<div class=\"btn radius  size-S ml-10\" onclick='dealmodal("+data.orderCancleApply.id+",\"" + data.orderCancleApply.order_id + "\")'><span class=\"list\" id='"+data.orderCancleApply.id+"' >驳回</span></div>")
            // $("#order_statue2").html("<div class=\"btn radius  size-S ml-10\" onclick='dealdemo("+data.orderCancleApply.id+")'><span class=\"list\" id='"+data.orderCancleApply.id+"' >跟进</span></div>")
            $("#order_statue2").html(" <div class=\"btn radius  size-S ml-10\" onclick='adopt("+data.orderCancleApply.id+",\"" + data.orderCancleApply.order_id + "\","+data.orderCancleApply.cancle_reason+")'><span class=\"list\" id='"+data.orderCancleApply.id+"' >通过</span></div>")
        }
    }else {
        if (data.orderCancleApply != null){
            $("#cancle_reason").html(data.orderCancleApply.cancle_reason);
            if(data.orderCancleApply.cancle_reason ==10){
                $("#cancle_reason").html('客户订购错误/计划有变');
            }else if(data.orderCancleApply.cancle_reason ==11){
                $("#cancle_reason").html('价格高');
            }else if(data.orderCancleApply.cancle_reason ==12){
                $("#cancle_reason").html('无法满足到货时效');
            }else if(data.orderCancleApply.cancle_reason ==13){
                $("#cancle_reason").html('支付问题');
            }else if(data.orderCancleApply.cancle_reason ==14){
                $("#cancle_reason").html('重复下单');
            }else if(data.orderCancleApply.cancle_reason ==15){
                $("#cancle_reason").html('暂时不需要了');
            }else if(data.orderCancleApply.cancle_reason ==16){
                $("#cancle_reason").html('订单信息有误');
            }else if(data.orderCancleApply.cancle_reason ==17){
                $("#cancle_reason").html('无货');
            }else if(data.orderCancleApply.cancle_reason ==18){
                $("#cancle_reason").html('其他');
            }else if(data.orderCancleApply.cancle_reason ==19){
                $("#cancle_reason").html('商品质量问题');
            }else if(data.orderCancleApply.cancle_reason ==20){
                $("#cancle_reason").html('价格错误');
            }else {
                $("#cancle_reason").html("");
            }
            //按钮展示
            if(data.orderCancleApply.deal_status==10&&data.orderCancleApply.cancel_apply_type==20){
                $("#order_statue1").html("<div class=\"btn radius  size-S ml-10\" onclick='dealmodal("+data.orderCancleApply.id+",\"" + data.orderCancleApply.order_id + "\")'><span class=\"list\" id='"+data.orderCancleApply.id+"' >驳回</span></div>")
                $("#order_statue2").html(" <div class=\"btn radius  size-S ml-10\" onclick='adopt("+data.orderCancleApply.id+",\"" + data.orderCancleApply.order_id + "\","+data.orderCancleApply.cancle_reason+")'><span class=\"list\" id='"+data.orderCancleApply.id+"' >通过</span></div>")
            }else {
                $("#order_statue1").html("<div class=\"btn radius  size-S ml-10\" onclick='dealmodal("+data.orderCancleApply.id+",\"" + data.orderCancleApply.order_id + "\")'><span class=\"list\" id='"+data.orderCancleApply.id+"' >驳回</span></div>")
                $("#order_statue2").html("<div class=\"btn radius  size-S ml-10\" onclick='dealdemo("+data.orderCancleApply.id+")'><span class=\"list\" id='"+data.orderCancleApply.id+"' >跟进</span></div>")
            }
        }else {
            $("#cancle_reason").html("");
        }
    }
}else {
    if (data.orderCancleApply != null){
        $("#cancle_reason").html(data.orderCancleApply.cancle_reason);
        if(data.orderCancleApply.cancle_reason ==10){
            $("#cancle_reason").html('客户订购错误/计划有变');
        }else if(data.orderCancleApply.cancle_reason ==11){
            $("#cancle_reason").html('价格高');
        }else if(data.orderCancleApply.cancle_reason ==12){
            $("#cancle_reason").html('无法满足到货时效');
        }else if(data.orderCancleApply.cancle_reason ==13){
            $("#cancle_reason").html('支付问题');
        }else if(data.orderCancleApply.cancle_reason ==14){
            $("#cancle_reason").html('重复下单');
        }else if(data.orderCancleApply.cancle_reason ==15){
            $("#cancle_reason").html('暂时不需要了');
        }else if(data.orderCancleApply.cancle_reason ==16){
            $("#cancle_reason").html('订单信息有误');
        }else if(data.orderCancleApply.cancle_reason ==17){
            $("#cancle_reason").html('无货');
        }else if(data.orderCancleApply.cancle_reason ==18){
            $("#cancle_reason").html('其他');
        }else if(data.orderCancleApply.cancle_reason ==19){
            $("#cancle_reason").html('商品质量问题');
        }else if(data.orderCancleApply.cancle_reason ==20){
            $("#cancle_reason").html('价格错误');
        }
        login_accounts= data.orderCancleApply.login_account
        //按钮展示
        if(data.orderCancleApply.deal_status==10&&data.orderCancleApply.cancel_apply_type==20){
            $("#order_statue1").html("<div class=\"btn radius  size-S ml-10\" onclick='dealmodal("+data.orderCancleApply.id+",\"" + data.orderCancleApply.order_id + "\")'><span class=\"list\" id='"+data.orderCancleApply.id+"' >驳回</span></div>")
            $("#order_statue2").html(" <div class=\"btn radius  size-S ml-10\" onclick='adopt("+data.orderCancleApply.id+",\"" + data.orderCancleApply.order_id + "\","+data.orderCancleApply.cancle_reason+")'><span class=\"list\" id='"+data.orderCancleApply.id+"' >通过</span></div>")
        }else {
            $("#order_statue1").html("<div class=\"btn radius  size-S ml-10\" onclick='dealmodal("+data.orderCancleApply.id+",\"" + data.orderCancleApply.order_id + "\")'><span class=\"list\" id='"+data.orderCancleApply.id+"' >驳回</span></div>")
            // $("#order_statue2").html("<div class=\"btn radius  size-S ml-10\" onclick='dealdemo("+data.orderCancleApply.id+")'><span class=\"list\" id='"+data.orderCancleApply.id+"' >跟进</span></div>")
            $("#order_statue2").html(" <div class=\"btn radius  size-S ml-10\" onclick='adopt("+data.orderCancleApply.id+",\"" + data.orderCancleApply.order_id + "\","+data.orderCancleApply.cancle_reason+")'><span class=\"list\" id='"+data.orderCancleApply.id+"' >通过</span></div>")
        }
    }else {
        $("#cancle_reason").html("");
    }
}
    $("#orderId").html(data.orderBase.order_id);
    $("#creatOrderTime").html(data.orderBase.created_at);
    //备注反显
    for(var i=0;i<data.listOrderRemark.length;i++){
        if(data.listOrderRemark[i].operate_type == 30){
            if(data.listOrderRemark[i].remark != null){
                $("#returnReason").html("全部拒收（"+data.listOrderRemark[i].remark+")")
            }else {
                $("#returnReason").html("全部拒收")
            }
            $("#closeOptioner").html(data.listOrderRemark[i].operate_username);
        }else if(data.listOrderRemark[i].operate_type == 40){
            $("#closeOptioner").html(data.listOrderRemark[i].operate_username);
            if(data.listOrderRemark[i].remark != null){
                $("#returnReason").html("全部退货（"+data.listOrderRemark[i].remark+")");
            }else {
                $("#returnReason").html("全部退货");
            }
        }else if(data.listOrderRemark[i].operate_type == 50){
            $("#customServiceRemark").text(data.listOrderRemark[i].remark);//客服备注
        }else if(data.listOrderRemark[i].operate_type == 60){
            $("#fareSeasonBox").show();
            $("#changeFareSeason").text(data.listOrderRemark[i].remark);//运费备注
        }
        if(data.listOrderRemark[i].operate_type == 20){
            if(data.listOrderRemark[i] == null) {
                $(".orderRemark textarea").val();
            } else {
                $(".orderRemark textarea").val(data.listOrderRemark[i].remark);
            }
        }
        if(data.listOrderRemark[i].operate_type == 10){
            if(data.listOrderRemark[i] == null) {
                $("#comfirmMoneyRemark").val();
            } else {
                $("#affirmMoney").css({
                    display:"none"
                })
                $("#comfirmMoneyRemark").html(data.listOrderRemark[i].remark);//确认认款备注
            }
        }
    }
    /*是否是异常订单*/
    if(data.orderAnomal == null){
        $("#abnormalTypeBox").hide();
    }else {
        var abnormalType = "";
        var abnormalTypeArr = [];
        var rowArr = data.orderAnomal.anomal_type.split(',');
        function getAbnormalType(typeCode) {
            switch(typeCode) {
                case "10":
                    return "大额订单";
                    break;
                case "20":
                    return "超占用订单";
                    break;
                case "30":
                    return "超赊欠额度订单";
                    break;
                case "40":
                    return "货到付款订单";
                    break;
                case  "50":
                    return "代客下单异常订单";
                    break;
                case  "60":
                    return "超卖订单";
                    break;
                case  "70":
                    return "低于成本价订单";
                    break;
            }
        }
        for(var i = 0; i < rowArr.length; i++) {
            abnormalTypeArr.push(getAbnormalType(rowArr[i]));
        }
        for(var j = 0; j < abnormalTypeArr.length; j++) {
            if(j < abnormalTypeArr.length - 1) {
                abnormalType += abnormalTypeArr[j] + ",";
            } else {
                abnormalType += abnormalTypeArr[j] + "";
            }
        }
        console.log(abnormalType)
        $("#abnormalType").html(abnormalType)
        $("#abnormalTypeBox").show();

    }
    /*取消订单记录*/
    if(data.orderCancle != null) {
        $("#cancleTime").html(data.orderCancle.created_at);
        $("#optioner").html(data.orderCancle.cancle_name);
        $("#cancle-reason").html(changeCancleReason(data.orderCancle.cancle_reason));
        $("#cancle-info").html(data.orderCancle.cancel_remark);
    }
    /*关闭订单记录*/
    if(data.orderRefund != null) {
        $("#closeTime").html(data.orderRefund.created_at);
        // $("#closeOptioner").html(data.orderRefund.operate_username);
        $("#close-reason").html(changeCloseReason(data.orderRefund.refund_reason));
        $("#close-info").html(data.orderRefund.refund_desc);
    }
    /*基本信息*/
    $("#buyer-name").html(data.orderBase.customer_name);
    $("#created-order-code").html(data.orderBase.login_account);
    $("#alisaAddress").html(data.orderExt.receiver_detail_address_alias);
    $("#receiver-address").html(data.orderExt.receiver_province_name + "" + data.orderExt.receiver_city_name + "" + data.orderExt.receiver_area_name + "" + data.orderExt.receiver_town_name + "" + data.orderExt.receiver_detail_address);
    $("#consignee").html(calculate(data.listAddressReceiver,1));
    $("#contact-way").html(calculate(data.listAddressReceiver,2));
    //授权收货人
    $("#cell-phone-number").html(calculate(data.listAddressReceiver,2));
    $("#sales-manager").html(data.orderExt.sales_manager_name);
    if(data.orderExt.platform==10){
        $("#platform").html("普通平台");
    }else if(data.orderExt.platform==20){
        $("#platform").html("签约平台");
    }

    //上门自提
    $("#self_take_in").html(data.self_take_in_str);
    $("#self_take_shop").html(data.orderExt.self_take_shop);
    $("#receiver_detail_address").html(data.orderExt.receiver_detail_address);
    $("#self_take_phone").html(data.orderExt.self_take_phone);

    $("#contact-phone").html(data.orderExt.sales_manager_phone);
    $("#email").html(data.orderExt.customer_email);

    /*鼠标移出事件*/
    $("#consignee").mouseover(function(){
        $("#mouseBox").show();
        $("#mouseBox").html(calculate(data.listAddressReceiver,1));
    }).mouseout(function(){
        $("#mouseBox").hide();
    })
    $("#cell-phone-number").mouseover(function(){
        $("#mouseBoxTwo").show();
        $("#mouseBoxTwo").html(calculate(data.listAddressReceiver,3))
    }).mouseout(function(){
        $("#mouseBoxTwo").hide();
    })
    //固话
    $("#linePhone").html(data.orderExt.customer_landline_phone);
    if(data.orderBase.role_name == " "){
        $("#replaceBox").hide();
    }else {
        $("#replace-man").html(data.orderBase.role_name);
    }
    /*支付与配送方式*/
    $("#pay-type").html(data.initPayWay);
    console.log(data.orderExt.final_sent_type)
    console.log(changeDeliveryMethodType(data.orderExt.final_sent_type))
    $("#delivery-method").html(data.orderExt.final_sent_type);
    if(data.orderExt.final_sent_type==10){
        $("#delivery-method").html('快递')
    }else if(data.orderExt.final_sent_type==20){
        $("#delivery-method").html('快运')
    }else if(data.orderExt.final_sent_type==30){
        $("#delivery-method").html('专车包车')
    }else if(data.orderExt.final_sent_type==40){
        $("#delivery-method").html('鑫方盛物流')
    }else if(data.orderExt.final_sent_type==50){
        $("#delivery-method").html('上门自提')
    } else if(data.orderExt.final_sent_type==52){
        $("#delivery-method").html('配送客户自提')
    }
    //运费
    $("#shippingfee").html((data.orderBase.init_shipping_fee).toFixed(2));
    var yunf=""
    if(data.orderCoupon!="") {
        if (data.orderBase.used_coupon == 10 && data.orderCoupon.coupon_type == 20) {
            if (data.orderBase.separate_shipping_fee == 10) {
                yunf = (data.orderBase.shipping_fee - data.orderCoupon.coupon_real_value).toFixed(2) + '元' + '&nbsp;&nbsp;' + "(运费单开)"
            } else {
                yunf = (data.orderBase.shipping_fee - data.orderCoupon.coupon_real_value).toFixed(2) + '元' + '&nbsp;&nbsp;' + "(运费分摊)"
            }

        } else {
            if (data.orderBase.separate_shipping_fee == 10) {
                yunf = (data.orderBase.shipping_fee).toFixed(2) + '元' + '&nbsp;&nbsp;' + "(运费单开)"
            } else {
                yunf = (data.orderBase.shipping_fee).toFixed(2) + '元' + '&nbsp;&nbsp;' + "(运费分摊)"
            }
        }
    }

console.log(yunf)
    $("#couponrealvalue").html(yunf);
    $("#freight").html((data.orderBase.shipping_fee).toFixed(2));
    //预计送达时间
    $("#predixt-delivery-time").html(data.may_arrived);
    if(data.orderExt.may_arrived_in =='1000-01-01 00:00:00'){
        $("#predixt-delivery-time").html("");
    }else if(data.may_arrived ==null){
        $("#predixt-delivery-time").html("");
    }else{
        $("#predixt-delivery-time").html(data.may_arrived);
    }

    //期望送达时间
    $("#wanna_arrived_in").html(data.wanna_arrived);
    if(data.wanna_arrived =='1000-01-01 00:00:00'){
        $("#wanna_arrived_in").html("");
    }else if(data.wanna_arrived==null){

        $("#wanna_arrived_in").html("");
    }else{
        $("#wanna_arrived_in").html(data.wanna_arrived);
    }
    //DC仓发货人
    if (data.orderExt.express_company==null){
        $("#express_company").html("")
    }else {
        $("#express_company").html(data.orderExt.express_company+data.orderExt.express_num);
    }
    //快递公司
    if (data.orderExt.express_company==null){
        $("#express_company2").html("")
    }else {
        $("#express_company2").html(data.orderExt.express_company);
    }
    //快递单号
    if (data.orderExt.express_num==null){
        $("#express_num").html("")
    }else {
        $("#express_num").html(data.orderExt.express_num);
    }
    //快运公司
    if (data.orderExt.express_company==null){
        $("#express_company3").html("")
    }else {
        $("#express_company3").html(data.orderExt.express_company);
    }
    //快运单号
    if (data.orderExt.express_num==null){
        $("#express_num3").html("")
    }else {
        $("#express_num3").html(data.orderExt.express_num);
    }


    //结算金额
    $("#settlement-amount").html(data.orderBase.paid_amount);
    //付款方式
    $("#money-type").html(data.payWay);

    //结算方式
    $("#settlement-method").html(data.settleWay);

    //司机名称和电话
    if (data.orderExt.driver_name==null){
        $("#driver-phone").html("")
    }else {
        $("#driver-phone").html(data.orderExt.driver_name+data.orderExt.driver_phone);
    }
    //配送员名称和电话
    if (data.orderExt.deliver_name==null){
        $("#distributor-phone").html("")
    }else {
        $("#distributor-phone").html(data.orderExt.deliver_name+data.orderExt.deliver_phone);
    }
    //开票状态判断
    if(data.orderInvoice==null){
        $('#invoicetype').text('未开');
    }else{
        if(data.orderInvoice.invoice_status==10||data.orderInvoice.invoice_status==20||data.orderInvoice.invoice_status==60){
            $('#invoicetype').text('未开');
        }else if(data.orderInvoice.invoice_status==30){
            $('#invoicetype').text('部分开');  
        }else if(data.orderInvoice.invoice_status==40||data.orderInvoice.invoice_status==50){
            $('#invoicetype').text('已开');              
        }
    }
    /*发票信息*/
    if(data.orderInvoice !=null){
        if(data.orderInvoice.invoice_type==null ||data.orderInvoice.invoice_type==''){
            $("#invoice-type").html("不开票")
        }
        if(data.orderInvoice.invoice_type==20 || data.orderInvoice.invoice_title=='个人'){
            $("#invoice-type").html('普通发票'+'&nbsp;&nbsp;'+data.orderInvoice.invoice_title)
        }else if(data.orderInvoice.invoice_type==20 || data.orderInvoice.invoice_title=='鑫方盛~'){
            $("#invoice-type").html('普通发票'+'&nbsp;&nbsp;'+data.orderInvoice.invoice_title+data.orderInvoice.taxpayer_identify_num)
        }else if(data.orderInvoice.invoice_type==10 ){
            $("#invoice-type").html('增值税专用发票'+'&nbsp;&nbsp;'+data.orderInvoice.invoice_title+'&nbsp;&nbsp;'+data.orderInvoice.taxpayer_identify_num+'&nbsp;&nbsp;'+data.orderInvoice.register_address+'&nbsp;&nbsp;'+data.orderInvoice.register_phone+'&nbsp;&nbsp;'+data.orderInvoice.open_bank+'&nbsp;&nbsp;'+data.orderInvoice.bank_account)
        }
        $("#invoice-title").html(data.orderInvoice.invoice_title);

        $("#invoice-title").html(data.orderInvoice.invoice_title);
        $("#invoice-content").html(data.orderInvoice.taxpayer_identify_num);
    }
    /*优惠券信息*/
    if(data.orderCoupon == null) {
        $("#couponInfo").html("无")
    } else {
        $("#couponInfo").html("满" + data.orderCoupon.use_condition + "元减" + data.orderCoupon.coupon_value + "元")
    }

    /*结算信息*/
    if(data.orderBase.separate_shipping_fee == 10){
        $("#goodsAmount").html((data.orderBase.final_total_amount - data.orderBase.shipping_fee-(data.total_promotion_value-data.full_amount_reduce_value-data.full_quantity_reduce_value)).toFixed(2)); //商品金额
        $("#fare").html((data.orderBase.shipping_fee).toFixed(2)); //运费
    }else {
        $("#goodsAmount").html((data.orderBase.final_total_amount - data.orderBase.shipping_fee-(data.total_promotion_value-data.full_amount_reduce_value-data.full_quantity_reduce_value)+data.orderBase.shipping_fee).toFixed(2)); //商品金额
        $("#fare").html("0.00"); //运费
    }
    var aaa = 0;
    $("#littleFare").html(aaa.toFixed(2)); //运费减免
    if(data.orderCoupon == null) {
        $("#conMoney").html(aaa.toFixed(2)); //优惠券
    } else {
        $("#conMoney").html((data.orderCoupon.coupon_real_value).toFixed(2)); //优惠券
    }
    //促销立减
    $("#cuxiao").html((data.full_amount_reduce_value+data.full_quantity_reduce_value).toFixed(2));
    $("#integral").html((data.orderBase.used_total_points).toFixed(2));
    $("#orderAmount").html((data.orderBase.paid_amount).toFixed(2)); //订单金额

    /*资质文件信息*/
    $("#copies").html(changeCopies(data.orderBase.quality_file_required,data.orderExt.file_copies,data.orderExt.original_file));
    /*商品信息*/
    var handStr = '';
    var hdStr = '';
    var hdStrdf=""
    var hdStrdfuu=""
    var hdSdfuu=""
    var warehouses=JSON.parse(sessionStorage.getItem("warehouses"))
    //满减金额商品
    if(data.fullAmountReduceOrderItemsMap!="" && data.fullAmountReduceOrderItemsMap!=null){
        var arr=data.fullAmountReduceOrderItemsMap
        $.each(arr,function (index,i) {
            //算出该活动的所有商品小计和优惠值
            let countMoney = 0;
            let promotionMoney = 0;
            $.each(arr[index],function(k,v){
                promotionMoney = Number(promotionMoney)+Number(v.promotion_value.toFixed(2));
                countMoney=Number(countMoney)+Number((v.sale_price * v.buyyer_count).toFixed(2));
            })
            let ruleStr = '<tr><td colspan="11"><div>' +
                '<span style="float: left;">'+arr[index][0].activity_rule+'</span>' +
                '<div style="float: right"><span style="float: left;">￥'+(countMoney).toFixed(2)+'</span><br>' +
                '<span style="float: left;">减：'+(promotionMoney).toFixed(2)+'</span></div>' +
                '</div></td></tr>';
            handStr +=ruleStr;

            $.each(arr[index],function(k,v){
                var ss=""
                $.each(warehouses.data,function(k,s){
                    if(data.orderBase.parent_warehouse_id==s.warehouseCode){
                        ss=s.warehouseName
                    }
                })
                //单价
                var price=v.sale_price
                var specialPrice=""
                if(v.activity_type == 10){
                    specialPrice=v.promotion_value/v.buyyer_count
                }
                price=(price-specialPrice).toFixed(2)

                //运费分摊
                var fares=""
                if(data.orderBase.separate_shipping_fee == 10) {
                    fares="0"
                }else {
                    fares=v.fare
                }
                //满减券分摊
                var couponvalues=""
                if(data.orderCoupon!="" && data.orderCoupon!=null){

                    if(data.orderCoupon.coupon_type == 10) {
                        couponvalues=v.coupon_value
                    }else {
                        couponvalues="0"
                    }
                }
                var substotle = (price* v.buyyer_count ).toFixed(2);
                    if (v.spu_id==0){
                        handStr+='<tr class="biaoge1">' +
                            '<td class="biaoge1-1"><div style="cursor:pointer;"><img title="" style="float: left;width: 100px;height: 100px;" name="" src="'+v.product_pic+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>'+v.sku_code+'</div><div>'+v.product_name+'</div><div>'+v.color+'</div><div>'+v.sku_info+'</div></div></div></td>' +
                            '<td class="biaoge1-1"><span id="handle_man">'+ss+'</span></td>' +
                            '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                            '<td class="biaoge1-3"><span id="create_time">' + v.receive_count + '' + v.unit_name + '</span></td>'+
                            '<td class="biaoge1-3"><span id="create_time">' + v.have_returned_count + '' + v.unit_name + '</span></td>'+
                            '<td class="biaoge1-3"><span id="create_time">' + price + '元/' + v.unit_name + '</span></td>'+
                            '<td class="biaoge1-3"><span id="create_time">'+couponvalues+'</span></td>'+
                            '<td class="biaoge1-3"><span id="create_time">'+fares+'</span></td>'+
                            '<td class="biaoge1-3"><span id="create_time">'+v.promotion_value+'</span></td>'+
                            '<td class="biaoge1-3"><span id="create_time">'+v.used_points+'</span></td>'+
                            '<td class="biaoge1-3"><span id="create_time">' + substotle + '元'+'</span></td>'+
                            '</tr>';
                    }else {
                        handStr+='<tr class="biaoge1">' +
                            '<td class="biaoge1-1"><div style="cursor:pointer;"><img title="点击跳转sku列表" onclick="goToGoodsDetail('+v.spu_id+')"  style="float: left;width: 100px;height: 100px;" name="" src="'+v.product_pic+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>'+v.sku_code+'</div><div>'+v.product_name+'</div><div>'+v.color+'</div><div>'+v.sku_info+'</div></div></div></td>' +
                            '<td class="biaoge1-1"><span id="handle_man">'+ss+'</span></td>' +
                            '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                            '<td class="biaoge1-3"><span id="create_time">' + v.receive_count + '' + v.unit_name + '</span></td>'+
                            '<td class="biaoge1-3"><span id="create_time">' + v.have_returned_count + '' + v.unit_name + '</span></td>'+
                            '<td class="biaoge1-3"><span id="create_time">' + price + '元/' + v.unit_name + '</span></td>'+
                            '<td class="biaoge1-3"><span id="create_time">'+couponvalues+'</span></td>'+
                            '<td class="biaoge1-3"><span id="create_time">'+fares+'</span></td>'+
                            '<td class="biaoge1-3"><span id="create_time">'+v.promotion_value+'</span></td>'+
                            '<td class="biaoge1-3"><span id="create_time">'+v.used_points+'</span></td>'+
                            '<td class="biaoge1-3"><span id="create_time">' + substotle + '元'+'</span></td>'+
                            '</tr>';
                    }
                }
            )
        })
    }
    //数量商品
    if(data.fullQuantityReduceOrderItemsMap!="" && data.fullQuantityReduceOrderItemsMap!=null){
        var arr=data.fullQuantityReduceOrderItemsMap
        $.each(arr,function (index,i) {
            //算出该活动的所有商品小计和优惠值
            let countMoney = 0;
            let promotionMoney = 0;
            $.each(arr[index],function(k,v){
                promotionMoney = Number(promotionMoney)+Number(v.promotion_value.toFixed(2));
                countMoney=Number(countMoney)+Number((v.sale_price * v.buyyer_count).toFixed(2));
            })

            let ruleStre = '<tr><td colspan="11"><div>' +
                '<span style="float: left;">'+arr[index][0].activity_rule+'</span>' +
                '<div style="float: right"><span style="float: left;">￥'+countMoney+'</span><br>' +
                '<span style="float: left;">减：'+promotionMoney+'</span></div>' +
                '</div></td></tr>';
            hdStrdf +=ruleStre;

            $.each(arr[index],function(k,v) {
                    console.log(arr[index])
                var ss=""
                $.each(warehouses.data,function(k,s){
                    if(data.orderBase.parent_warehouse_id==s.warehouseCode){
                        ss=s.warehouseName
                    }
                })
                //单价
                var price=v.sale_price
                var specialPrice=""
                if(v.activity_type == 10){
                    specialPrice=v.promotion_value/v.buyyer_count
                }
                price=(price-specialPrice).toFixed(2)

                //运费分摊
                var fares=""
                if(data.orderBase.separate_shipping_fee == 10) {
                    fares="0"
                }else {
                    fares=v.fare

                }
                //满减券分摊
                var couponvalues=""
                if(data.orderCoupon!="" && data.orderCoupon!=null){

                    if(data.orderCoupon.coupon_type == 10) {
                        couponvalues=v.coupon_value
                    }else {
                        couponvalues="0"
                    }
                }
                var substotle = (price* v.buyyer_count ).toFixed(2);
                    if (v.spu_id == 0) {
                        hdStrdf += '<tr class="biaoge1">' +
                            '<td class="biaoge1-1"><div style="cursor:pointer;"><img title="" style="float: left;width: 100px;height: 100px;" name="" src="' + v.product_pic + '" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.color + '</div><div>' + v.sku_info + '</div></div></div></td>' +
                            '<td class="biaoge1-1"><span id="handle_man">' + ss + '</span></td>' +
                            '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + v.receive_count + '' + v.unit_name + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + v.have_returned_count + '' + v.unit_name + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + price + '元/' + v.unit_name + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + couponvalues + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + fares + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + v.promotion_value + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">'+v.used_points+'</span></td>'+
                            '<td class="biaoge1-3"><span id="create_time">' + substotle + '元' + '</span></td>' +
                            '</tr>';
                    }else {
                        hdStrdf += '<tr class="biaoge1">' +
                            '<td class="biaoge1-1"><div style="cursor:pointer;"><img title="点击跳转sku列表" onclick="goToGoodsDetail('+v.spu_id+')"  style="float: left;width: 100px;height: 100px;" name="" src="' + v.product_pic + '" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.color + '</div><div>' + v.sku_info + '</div></div></div></td>' +
                            '<td class="biaoge1-1"><span id="handle_man">' + ss + '</span></td>' +
                            '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + v.receive_count + '' + v.unit_name + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + v.have_returned_count + '' + v.unit_name + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + price + '元/' + v.unit_name + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + couponvalues + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + fares + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + v.promotion_value + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">'+v.used_points+'</span></td>'+
                            '<td class="biaoge1-3"><span id="create_time">' + substotle + '元' + '</span></td>' +
                            '</tr>';
                    }
                }
            )
        })
    }
    //特价商品
    if(data.specialPriceOrderItemsList !="" && data.specialPriceOrderItemsList!=null){
        var arr=data.specialPriceOrderItemsList

        //算出该活动的所有商品小计和优惠值
        let ii =""
        let ruleStret = '<tr><td colspan="11"><div>' +
            '<span style="float: left;">'+ii+'</span>' +
            '</div></td></tr>';
        hdStrdfuu +=ruleStret;

        $.each(arr,function(k,v){
            var ss=""
            $.each(warehouses.data,function(k,s){
                if(data.orderBase.parent_warehouse_id==s.warehouseCode){
                    ss=s.warehouseName
                }
            })
            //单价
            var price=v.sale_price
            var specialPrice=""
            if(v.activity_type == 10){
                specialPrice=v.promotion_value/v.buyyer_count
            }
            price=(price-specialPrice).toFixed(2)

            //运费分摊
            var fares=""
            if(data.orderBase.separate_shipping_fee == 10) {
                fares="0"
            }else {
                fares=v.fare

            }
            //满减券分摊
            var couponvalues=""
            if(data.orderCoupon!="" && data.orderCoupon!=null){

                if(data.orderCoupon.coupon_type == 10) {
                    couponvalues=v.coupon_value
                }else {
                    couponvalues="0"
                }
            }
            var substotle = (price * v.buyyer_count ).toFixed(2);
                if (v.spu_id == 0) {
                    hdStrdfuu+='<tr class="biaoge1">' +
                        '<td class="biaoge1-1"><div style="cursor:pointer;"><img title="" style="float: left;width: 100px;height: 100px;" name="" src="'+v.product_pic+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>'+v.sku_code+'</div><div>'+v.product_name+'</div><div>'+v.color+'</div><div>'+v.sku_info+'</div></div></div></td>' +
                        '<td class="biaoge1-1"><span id="handle_man">'+ss+'</span></td>' +
                        '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                        '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">' + v.receive_count + '' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">' + v.have_returned_count + '' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><div><input style="width: 32px;background-color: yellow;" value="特价" readonly="readonly"></div><span id="create_time">' + price + '元/' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">'+couponvalues+'</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">'+fares+'</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">'+"0"+'</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">'+v.used_points+'</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">' + substotle + '元'+'</span></td>'+
                        '</tr>';
                }else {
                    hdStrdfuu+='<tr class="biaoge1">' +
                        '<td class="biaoge1-1"><div style="cursor:pointer;"><img title="点击跳转sku列表" onclick="goToGoodsDetail('+v.spu_id+')" style="float: left;width: 100px;height: 100px;" name="" src="'+v.product_pic+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>'+v.sku_code+'</div><div>'+v.product_name+'</div><div>'+v.color+'</div><div>'+v.sku_info+'</div></div></div></td>' +
                        '<td class="biaoge1-1"><span id="handle_man">'+ss+'</span></td>' +
                        '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                        '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">' + v.receive_count + '' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">' + v.have_returned_count + '' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><div><input style="width: 32px;background-color: yellow;" value="特价" readonly="readonly"></div><span id="create_time">' + price + '元/' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">'+couponvalues+'</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">'+fares+'</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">'+"0"+'</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">'+v.used_points+'</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">' + substotle + '元'+'</span></td>'+
                        '</tr>';
                }
            }
        )
    }

    if(data.normalPriceOrderItemsList !="" && data.normalPriceOrderItemsList!=null){
        var arr=data.normalPriceOrderItemsList
        //算出该活动的所有商品小计和优惠值
        let ii =""
        let ruleStret = '<tr><td colspan="11"><div>' +
            '<span style="float: left;">'+ii+'</span>' +
            '</div></td></tr>';
        hdSdfuu +=ruleStret;
        $.each(arr,function(k,v){
            var ss=""
            $.each(warehouses.data,function(k,s){
                if(data.orderBase.parent_warehouse_id==s.warehouseCode){
                    ss=s.warehouseName
                }
            })
            //单价
            var price=v.sale_price
            var specialPrice=""
            if(v.activity_type == 10){
                specialPrice=v.promotion_value/v.buyyer_count
            }
            price=(price-specialPrice).toFixed(2)

            //运费分摊
            var fares=""
            if(data.orderBase.separate_shipping_fee == 10) {
                fares="0"
            }else {
                fares=v.fare
            }
            //满减券分摊
            var couponvalues=""
            if(data.orderCoupon!="" && data.orderCoupon!=null){

                if(data.orderCoupon.coupon_type == 10) {
                    couponvalues=v.coupon_value
                }else {
                    couponvalues="0"
                }
            }
            var substotle = (price* v.buyyer_count ).toFixed(2);
                if (v.spu_id == 0) {
                    hdSdfuu+='<tr class="biaoge1">' +
                        '<td class="biaoge1-1"><div style="cursor:pointer;"><img title="" style="float: left;width: 100px;height: 100px;" name="" src="'+v.product_pic+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>'+v.sku_code+'</div><div>'+v.product_name+'</div><div>'+v.color+'</div><div>'+v.sku_info+'</div></div></div></td>' +
                        '<td class="biaoge1-1"><span id="handle_man">'+ss+'</span></td>' +
                        '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                        '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">' + v.receive_count + '' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">' + v.have_returned_count + '' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">' + price + '元/' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">'+couponvalues+'</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">'+fares+'</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">'+v.promotion_value+'</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">'+v.used_points+'</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">' + substotle + '元'+'</span></td>'+
                        '</tr>';
                }else {
                    hdSdfuu+='<tr class="biaoge1">' +
                        '<td class="biaoge1-1"><div style="cursor:pointer;"><img title="点击跳转sku列表" onclick="goToGoodsDetail('+v.spu_id+')" style="float: left;width: 100px;height: 100px;" name="" src="'+v.product_pic+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>'+v.sku_code+'</div><div>'+v.product_name+'</div><div>'+v.color+'</div><div>'+v.sku_info+'</div></div></div></td>' +
                        '<td class="biaoge1-1"><span id="handle_man">'+ss+'</span></td>' +
                        '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                        '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">' + v.receive_count + '' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">' + v.have_returned_count + '' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">' + price + '元/' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">'+couponvalues+'</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">'+fares+'</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">'+v.promotion_value+'</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">'+v.used_points+'</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">' + substotle + '元'+'</span></td>'+
                        '</tr>';
                }
            }
        )
    }
    $("#datatable").find("tbody").append($(handStr));
    $("#datatable").find("tbody").append($(hdStrdf));
    $("#datatable").find("tbody").append($(hdStrdfuu));
    $("#datatable").find("tbody").append($(hdSdfuu));
}

/*跳转退货订单详情*/
function returnOrderInfo(title,url,returnId,orderiiid){
    sessionStorage.setItem("returnId",returnId);
    sessionStorage.setItem("returnOrderId",orderiiid);
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}
/*订单备注编辑*/
var oldVal = "";

function toEdit() {
    oldVal = $(".orderRemark textarea").val();
    $("#isSaveFalse").css({
        display: "none"
    });
    $("#isSaveTrue").css({
        display: "block"
    });
    $(".orderRemark textarea").removeAttr("readonly");
}

function toCancle() {
    $(".orderRemark textarea").val(oldVal);
    $("#isSaveFalse").css({
        display: "block"
    });
    $("#isSaveTrue").css({
        display: "none"
    });
    $(".orderRemark textarea").css({
        border: "1px #ddd solid"
    });
    $(".errorMsg").css({
        display: "none"
    });
    $(".orderRemark textarea").attr("readonly", "readonly");
}
/*跳转退货订单详情*/
function returnOrderInfo(title,url,returnId,orderId){
    sessionStorage.setItem("returnId",returnId);
    sessionStorage.setItem("returnOrderId",orderId);
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}
function remarkToSave() {
    if($(".orderRemark textarea").val().length > 500) {
        $(".orderRemark textarea").css({
            border: "1px red solid"
        });
        $(".errorMsg").css({
            display: "inline"
        });

    } else {
        $(".orderRemark textarea").css({
            border: "1px #ddd solid"
        });
        $(".errorMsg").css({
            display: "none"
        });
        var orderDetail = JSON.parse(sessionStorage.getItem("orderDetail"));
        var orderState = orderDetail.orderBase.order_status;

        function btnDisplay() {
            $("#isSaveFalse").css({
                display: "block"
            });
            $("#isSaveTrue").css({
                display: "none"
            });
            $(".orderRemark textarea").attr("readonly", "readonly");
        }
        /*进行添加备注请求*/
        btnDisplay();
        $.ajax({
            contentType: "application/json",
            type: "POST",
            url: root.orderInter.order_saveOrderRemark,
            cache: false, //禁用缓存
            dataType: "json",
            data: JSON.stringify({
                bus_id: orderDetail.orderBase.order_id,
                operate_userid: JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
                operate_username: JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
                remark: $("#comfirmRemark").val()

            }),
            success: function(result) {
                location.replace(location.href);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest);
            }
        });
    }
}

/*详细信息编辑*/
function requireUpdataInter(updataData) {
    $.ajax({
        contentType: "application/json",
        type: "POST",
        url: root.orderInter.order_edit,
        cache: false, //禁用缓存
        dataType: "json",
        data: updataData,
        success: function(result) {
            if(result.code == 0) {
                $("#addressInpBox").css({
                    display: "none",
                });
                location.replace(location.href);
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
        }
    });
}

function updataDisplay(ids) {
    $(ids).css({
        display: "block",
    });
}

function updataSure(val) {
    var orderDetail = JSON.parse(sessionStorage.getItem("orderDetail"));
    switch(val) {
        /*修改那个标签*/
        case "#addressInp":
            /*收货地址*/
            var updataData = JSON.stringify({
                order_id: orderDetail.orderBase.order_id,
                receiver_detail_address: $('#addressInp').val(),
            });
            requireUpdataInter(updataData);
            break;
        case "#consigneeInp":
            /*收货人*/
            var updataData = JSON.stringify({
                order_id: orderDetail.orderBase.order_id,
                received_name: $('#consigneeInp').val(),
            });
            requireUpdataInter(updataData);
            break;

        case "#alisaAddressInp":
            /*地址别名*/
            var updataData = JSON.stringify({
                order_id: orderDetail.orderBase.order_id,
                receiver_detail_address_alias: $('#alisaAddressInp').val(),
            });
            requireUpdataInter(updataData);
            break;
        case "#emailInp":
            /*邮箱*/
            var updataData = JSON.stringify({
                order_id: orderDetail.orderBase.order_id,
                customer_email: $('#emailInp').val(),
            });
            requireUpdataInter(updataData);
            break;
        case "#phoneInp":
            /*手机号*/
            var updataData = JSON.stringify({
                order_id: orderDetail.orderBase.order_id,
                received_phone: $('#phoneInp').val(),
            });
            requireUpdataInter(updataData);
            break;
        case "#linePhoneInp":
            /*固定电话*/
            var updataData = JSON.stringify({
                order_id: orderDetail.orderBase.order_id,
                customer_landline_phone: $('#linePhoneInp').val(),
            });
            requireUpdataInter(updataData);
            break;
    }
}

function updataCancel() {

    $("#alisaAddressInpBox").css({
        display: "none",
    });
}
function updataCancel1() {
    $("#addressInpBox").css({
        display: "none",
    });
}
function updataCancel2() {

    $("#consigneeInpBox").css({
        display: "none",
    });
}
function updataCancel3() {
    $("#emailInpBox").css({
        display: "none",
    });
}
function updataCancel4() {
    $("#phoneInpBox").css({
        display: "none",
    });
}
function updataCancel5() {
    $("#linePhoneInpBox").css({
        display: "none",
    });
}

function goToGoodsDetail(spuId) {
    sessionStorage.setItem("spuId", spuId);
    sessionStorage.setItem("spuId_order", spuId);
    var index = layer.open({
        type: 2,
        title: "Code详情",
        content: "../../goods/goods-sku.html"
    });
    layer.full(index);
}

//驳回弹框
var index=0;
function dealmodal(id,order_id,val) {
    //权限判断3
    var warehouse_ids =sessionStorage.getItem("regions")//主仓库
    var sales_manager_ids = sessionStorage.getItem("personnels")//人员
    var companys_ids=sessionStorage.getItem("companys")//客户归属

    //都没勾选
    if(warehouse_ids=="" && companys_ids=="") {
        $.Huimodalalert('暂无此订单处理权限！', 2000);
    }
    //只勾选仓
    if(warehouse_ids!="" && companys_ids=="") {

        var warehouse_idsAll=warehouse_ids.split(",");
        var isHas = false;
        for (var i = 0; i < warehouse_idsAll.length; i++) {

            if (warehouse_idsAll[i]==JSON.parse(sessionStorage.getItem("orderDetail")).orderBase.parent_warehouse_id) {
                var curInd = layer.confirm('<span id="status" style="width:200px;height:100px;resize: none;" maxlength="200" >您确定要驳回吗</span>', {offset:'230px',title:'提示',btn: ['确定', '取消']}, function(index){

                    finish1(id,order_id,curInd,val)
                    layer.close(curInd);
                },function(){
                    layer.close(curInd);

                });
                isHas = true;
                break;
            }
        }
        if(!isHas){
            $.Huimodalalert('暂无此订单处理权限！', 2000);
        }
    }

    //只勾线分公司
    if(warehouse_ids=="" && companys_ids!="") {
        //有没有勾选分公司
        //子仓库不为空,人员为空时
        if( companys_ids!=""&& sales_manager_ids=="") {
            var companys_idAll=companys_ids.split(",");
            var isHas = false;
                for (var t = 0; t < companys_idAll.length; t++) {
                    if ( companys_idAll[t]==JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.belong_groupId) {
                        var curInd = layer.confirm('<span id="status" style="width:200px;height:100px;resize: none;" maxlength="200" >您确定要驳回吗</span>', {offset:'230px',title:'提示',btn: ['确定', '取消']}, function(index){

                            finish1(id,order_id,curInd,val)
                            layer.close(curInd);
                        },function(){
                            layer.close(curInd);
                        });
                        isHas = true;
                        break;
                    }
            }
            if(!isHas){
                $.Huimodalalert('暂无此订单处理权限！', 2000);
            }
        }
        //子仓库,人员不为空时
        if( companys_ids!=""&& sales_manager_ids!="") {

            var sales_manager_idsAll=sales_manager_ids.split(",");
            var companys_idAll=companys_ids.split(",");
            var isHas = false;
                for (var j = 0; j < sales_manager_idsAll.length; j++) {
                    for (var t = 0; t < companys_idAll.length; t++) {
                        if ( sales_manager_idsAll[j]==JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.sales_manager_id || companys_idAll[t]==JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.belong_groupId){
                            isHas = true;
                            break;
                        }
                    }

            }
            if(!isHas){
                $.Huimodalalert('暂无此订单处理权限！', 2000);
            }else {
                var curInd = layer.confirm('<span id="status" style="width:200px;height:100px;resize: none;" maxlength="200" >您确定要驳回吗</span>', {offset:'230px',title:'提示',btn: ['确定', '取消']}, function(index){

                    finish1(id,order_id,curInd,val)
                    layer.close(curInd);
                },function(){
                    layer.close(curInd);
                });
            }
        }
    }
    //仓和分公司
    if(warehouse_ids!="" && companys_ids!="") {
        //主仓不为空，子仓库不为空,人员为空时
        if(warehouse_ids!="" && companys_ids!=""&& sales_manager_ids=="") {
            var warehouse_idsAll=warehouse_ids.split(",");

            var companys_idAll=companys_ids.split(",");
            var isHas = false;
            for (var d = 0; d < warehouse_idsAll.length; d++) {

                    for (var t = 0; t < companys_idAll.length; t++) {
                        if (warehouse_idsAll[d]==JSON.parse(sessionStorage.getItem("orderDetail")).orderBase.parent_warehouse_id ||  companys_idAll[t]==JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.belong_groupId) {
                            isHas = true;
                            break;
                        }
                    }
            }
            if(!isHas){
                $.Huimodalalert('暂无此订单处理权限！', 2000);
            }else {
                var curInd = layer.confirm('<span id="status" style="width:200px;height:100px;resize: none;" maxlength="200" >您确定要驳回吗</span>', {offset:'230px',title:'提示',btn: ['确定', '取消']}, function(index){

                    finish1(id,order_id,curInd,val)
                    layer.close(curInd);
                },function(){
                    layer.close(curInd);

                });
            }
        }
        //主仓不为空，子仓库不为空,人员不为空时
        if(warehouse_ids!="" && companys_ids!=""&& sales_manager_ids!="") {
            var warehouse_idsAll=warehouse_ids.split(",");

            var sales_manager_idsAll=sales_manager_ids.split(",");
            var companys_idAll=companys_ids.split(",");
            var isHas = false;
            for (var d = 0; d < warehouse_idsAll.length; d++) {

                    for (var f = 0; f < sales_manager_idsAll.length; f++) {
                        for (var t = 0; t < companys_idAll.length; t++) {
                            if (warehouse_idsAll[d]==JSON.parse(sessionStorage.getItem("orderDetail")).orderBase.parent_warehouse_id ||  sales_manager_idsAll[f]==JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.sales_manager_id || companys_idAll[t]==JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.belong_groupId) {


                                isHas = true;
                                break;
                            }
                        }
                }
            }
            if(!isHas){
                $.Huimodalalert('暂无此订单处理权限！', 2000);
            }else {
                var curInd = layer.confirm('<span id="status" style="width:200px;height:100px;resize: none;" maxlength="200" >您确定要驳回吗</span>', {offset:'230px',title:'提示',btn: ['确定', '取消']}, function(index){

                    finish1(id,order_id,curInd,val)
                    layer.close(curInd);
                },function(){
                    layer.close(curInd);

                });
            }
        }

    }
}
function finish1(id,order_id,val){
    var target = document.getElementById(''+id+'');
    /*target.parentElement.parentElement.parentElement.previousElementSibling.innerHTML='关闭';*/
    console.log(target)

    var reason=$('#reason'+id+order_id+'').val();
    if(reason!=''){
        $.ajax({
            contentType: "application/json;charset=UTF-8",
            url:root.orderInter.order_rejectCancleApply,
            cache: false,  //禁用缓存
            type: "POST",
            dataType:'json',
            data: JSON.stringify({
                "id":sessionStorage.getItem("pid"),
                order_id:order_id
            }),
            success: function (data) {
                console.log(data)
                target.onclick = null;
                target.setAttribute("onclick", 'confirm('+id+')')
                /*target.parentElement.parentElement.parentElement.previousElementSibling.innerHTML='关闭'*/
                getOrderDetai();

            },
            error: function () {
                $.Huimodalalert('失败！',2000);
            }
        })}
    else{
        $.Huimodalalert('处理结果不能为空！',2000);
    };
    layer.close(index);
}

function dealdemo(id,val) {
    //权限判断3
    var warehouse_ids =sessionStorage.getItem("regions")//主仓库

    var sales_manager_ids = sessionStorage.getItem("personnels")//人员
    var companys_ids=sessionStorage.getItem("companys")//客户归属

    //都没勾选
    if(warehouse_ids=="" && companys_ids=="") {
        $.Huimodalalert('暂无此订单处理权限！', 2000);
    }
    //只勾选仓
    if(warehouse_ids!="" && companys_ids=="") {

        var warehouse_idsAll=warehouse_ids.split(",");
        var isHas = false;
        for (var i = 0; i < warehouse_idsAll.length; i++) {

            if (warehouse_idsAll[i]==JSON.parse(sessionStorage.getItem("orderDetail")).orderBase.parent_warehouse_id) {
                layer.msg('客服跟进处理！');
                $.ajax({
                    contentType: "application/json;charset=UTF-8",
                    url:root.orderInter.order_followCancleApply,
                    cache: false,  //禁用缓存
                    type: "POST",
                    dataType:'json',
                    data: JSON.stringify({
                        "id":id,
                    }),
                    success: function (data) {

                        getOrderDetai();
                    },
                    error: function () {
                        $.Huimodalalert('失败！',2000);
                    }
                })
                isHas = true;
                break;
            }
        }
        if(!isHas){
            $.Huimodalalert('暂无此订单处理权限！', 2000);
        }
    }

    //只勾线分公司
    if(warehouse_ids=="" && companys_ids!="") {
        //有没有勾选分公司
        //子仓库不为空,人员为空时
        if( companys_ids!=""&& sales_manager_ids=="") {

            var companys_idAll=companys_ids.split(",");
            var isHas = false;

                for (var t = 0; t < companys_idAll.length; t++) {
                    if ( companys_idAll[t]==JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.belong_groupId) {

                        layer.msg('客服跟进处理！');
                        $.ajax({
                            contentType: "application/json;charset=UTF-8",
                            url:root.orderInter.order_followCancleApply,
                            cache: false,  //禁用缓存
                            type: "POST",
                            dataType:'json',
                            data: JSON.stringify({
                                "id":id,
                            }),
                            success: function (data) {

                                getOrderDetai();
                            },
                            error: function () {
                                $.Huimodalalert('失败！',2000);
                            }
                        })
                        isHas = true;
                        break;
                    }

            }
            if(!isHas){
                $.Huimodalalert('暂无此订单处理权限！', 2000);
            }
        }
        //子仓库,人员不为空时
        if( companys_ids!=""&& sales_manager_ids!="") {

            var sales_manager_idsAll=sales_manager_ids.split(",");
            var companys_idAll=companys_ids.split(",");
            var isHas = false;
            for (var j = 0; j < sales_manager_idsAll.length; j++) {
                for (var t = 0; t < companys_idAll.length; t++) {
                    if ( sales_manager_idsAll[j]==JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.sales_manager_id || companys_idAll[t]==JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.belong_groupId){
                        isHas = true;
                        break;
                    }
                }
            }
            if(!isHas){
                $.Huimodalalert('暂无此订单处理权限！', 2000);
            }else {
                layer.msg('客服跟进处理！');
                $.ajax({
                    contentType: "application/json;charset=UTF-8",
                    url:root.orderInter.order_followCancleApply,
                    cache: false,  //禁用缓存
                    type: "POST",
                    dataType:'json',
                    data: JSON.stringify({
                        "id":id,
                    }),
                    success: function (data) {
                        getOrderDetai();
                    },
                    error: function () {
                        $.Huimodalalert('失败！',2000);
                    }
                })
            }
        }
    }
    //仓和分公司
    if(warehouse_ids!="" && companys_ids!="") {
        //主仓不为空，子仓库不为空,人员为空时
        if(warehouse_ids!="" && companys_ids!=""&& sales_manager_ids=="") {
            var warehouse_idsAll=warehouse_ids.split(",");
            var companys_idAll=companys_ids.split(",");
            var isHas = false;
            for (var d = 0; d < warehouse_idsAll.length; d++) {
                for (var t = 0; t < companys_idAll.length; t++) {
                    if (warehouse_idsAll[d]==JSON.parse(sessionStorage.getItem("orderDetail")).orderBase.parent_warehouse_id ||  companys_idAll[t]==JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.belong_groupId) {
                        isHas = true;
                        break;
                    }
                }
            }
            if(!isHas){
                $.Huimodalalert('暂无此订单处理权限！', 2000);
            }else {
                layer.msg('客服跟进处理！');
                $.ajax({
                    contentType: "application/json;charset=UTF-8",
                    url:root.orderInter.order_followCancleApply,
                    cache: false,  //禁用缓存
                    type: "POST",
                    dataType:'json',
                    data: JSON.stringify({
                        "id":id,
                    }),
                    success: function (data) {
                        getOrderDetai();
                    },
                    error: function () {
                        $.Huimodalalert('失败！',2000);
                    }
                })
            }
        }
        //主仓不为空，子仓库不为空,人员不为空时
        if(warehouse_ids!="" && companys_ids!=""&& sales_manager_ids!="") {
            var warehouse_idsAll=warehouse_ids.split(",");
            var sales_manager_idsAll=sales_manager_ids.split(",");
            var companys_idAll=companys_ids.split(",");
            var isHas = false;
            for (var d = 0; d < warehouse_idsAll.length; d++) {
                for (var f = 0; f < sales_manager_idsAll.length; f++) {
                    for (var t = 0; t < companys_idAll.length; t++) {
                        if (warehouse_idsAll[d]==JSON.parse(sessionStorage.getItem("orderDetail")).orderBase.parent_warehouse_id ||  sales_manager_idsAll[f]==JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.sales_manager_id || companys_idAll[t]==JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.belong_groupId) {
                            isHas = true;
                            break;
                        }
                    }
                }
            }
            if(!isHas){
                $.Huimodalalert('暂无此订单处理权限！', 2000);
            }else {
                layer.msg('客服跟进处理！');
                $.ajax({
                    contentType: "application/json;charset=UTF-8",
                    url:root.orderInter.order_followCancleApply,
                    cache: false,  //禁用缓存
                    type: "POST",
                    dataType:'json',
                    data: JSON.stringify({
                        "id":id,
                    }),
                    success: function (data) {
                        getOrderDetai();
                    },
                    error: function () {
                        $.Huimodalalert('失败！',2000);
                    }
                })
            }
        }

    }
}

//退货申请单
var isIngReturn = false;
function returnGoods1(title) {
    //权限判断3
    var warehouse_ids =sessionStorage.getItem("regions")//主仓库
    var sales_manager_ids = sessionStorage.getItem("personnels")//人员
    var companys_ids=sessionStorage.getItem("companys")//客户归属
    //都没勾选
    if(warehouse_ids=="" && companys_ids=="") {
        $.Huimodalalert('暂无此订单处理权限！', 2000);
    }
    //只勾选仓
    if(warehouse_ids!="" && companys_ids=="") {
        var warehouse_idsAll=warehouse_ids.split(",");
        var isHas = false;
        for (var i = 0; i < warehouse_idsAll.length; i++) {
            if (warehouse_idsAll[i]==JSON.parse(sessionStorage.getItem("orderDetail")).orderBase.parent_warehouse_id) {
                if(isIngReturn){
                    // layer.msg('请求已提交，请勿重复点击！');
                    return false;
                }
                isIngReturn = true;
                getOrderDetai();
                setTimeout(function () {
                    var orderDetail = JSON.parse(sessionStorage.getItem("orderDetail"));
                    var orderState = orderDetail.orderBase.order_status;

                    var url = "orderSuccess_refund2.html";

                    var index = layer.open({
                        type: 2,
                        title: title,
                        content: url
                    });
                    layer.full(index);
                },200)
                isHas = true;
                break;
            }
        }
        if(!isHas){
            $.Huimodalalert('暂无此订单处理权限！', 2000);
        }
    }

    //只勾线分公司
    if(warehouse_ids=="" && companys_ids!="") {
        //有没有勾选分公司
        //子仓库不为空,人员为空时
        if( companys_ids!=""&& sales_manager_ids=="") {

            var companys_idAll=companys_ids.split(",");
            var isHas = false;
            for (var t = 0; t < companys_idAll.length; t++) {
                if ( companys_idAll[t]==JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.belong_groupId) {

                    if(isIngReturn){
                        // layer.msg('请求已提交，请勿重复点击！');
                        return false;
                    }
                    isIngReturn = true;
                    getOrderDetai();
                    setTimeout(function () {
                        var orderDetail = JSON.parse(sessionStorage.getItem("orderDetail"));
                        var orderState = orderDetail.orderBase.order_status;
                        var url = "orderSuccess_refund2.html";
                        var index = layer.open({
                            type: 2,
                            title: title,
                            content: url
                        });
                        layer.full(index);
                    },200)
                    isHas = true;
                    break;
                }
            }
            if(!isHas){
                $.Huimodalalert('暂无此订单处理权限！', 2000);
            }
        }
        //子仓库,人员不为空时
        if( companys_ids!=""&& sales_manager_ids!="") {
            var sales_manager_idsAll=sales_manager_ids.split(",");
            var companys_idAll=companys_ids.split(",");
            var isHas = false;
            for (var j = 0; j < sales_manager_idsAll.length; j++) {
                for (var t = 0; t < companys_idAll.length; t++) {
                    if ( sales_manager_idsAll[j]==JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.sales_manager_id || companys_idAll[t]==JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.belong_groupId){

                        isHas = true;
                        break;
                    }

                }
            }
            if(!isHas){
                $.Huimodalalert('暂无此订单处理权限！', 2000);
            }else {
                if(isIngReturn){
                    // layer.msg('请求已提交，请勿重复点击！');
                    return false;
                }
                isIngReturn = true;
                getOrderDetai();
                setTimeout(function () {
                    var orderDetail = JSON.parse(sessionStorage.getItem("orderDetail"));
                    var orderState = orderDetail.orderBase.order_status;
                    var url = "orderSuccess_refund2.html";
                    var index = layer.open({
                        type: 2,
                        title: title,
                        content: url
                    });
                    layer.full(index);
                },200)
            }
        }
    }
    //仓和分公司
    if(warehouse_ids!="" && companys_ids!="") {
        //主仓不为空，子仓库不为空,人员为空时
        if(warehouse_ids!="" && companys_ids!=""&& sales_manager_ids=="") {
            var warehouse_idsAll=warehouse_ids.split(",");

            var companys_idAll=companys_ids.split(",");
            var isHas = false;
            for (var d = 0; d < warehouse_idsAll.length; d++) {
                for (var t = 0; t < companys_idAll.length; t++) {
                    if (warehouse_idsAll[d]==JSON.parse(sessionStorage.getItem("orderDetail")).orderBase.parent_warehouse_id ||  companys_idAll[t]==JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.belong_groupId) {
                        isHas = true;
                        break;
                    }
                }
            }
            if(!isHas){
                $.Huimodalalert('暂无此订单处理权限！', 2000);
            }else {
                if(isIngReturn){
                    // layer.msg('请求已提交，请勿重复点击！');
                    return false;
                }
                isIngReturn = true;
                getOrderDetai();
                setTimeout(function () {
                    var orderDetail = JSON.parse(sessionStorage.getItem("orderDetail"));
                    var orderState = orderDetail.orderBase.order_status;
                    var url = "orderSuccess_refund2.html";
                    var index = layer.open({
                        type: 2,
                        title: title,
                        content: url
                    });
                    layer.full(index);
                },200)
            }
        }
        //主仓不为空，子仓库不为空,人员不为空时
        if(warehouse_ids!="" && companys_ids!=""&& sales_manager_ids!="") {
            var warehouse_idsAll=warehouse_ids.split(",");
            var sales_manager_idsAll=sales_manager_ids.split(",");
            var companys_idAll=companys_ids.split(",");
            var isHas = false;
            for (var d = 0; d < warehouse_idsAll.length; d++) {
                for (var f = 0; f < sales_manager_idsAll.length; f++) {
                    for (var t = 0; t < companys_idAll.length; t++) {
                        if (warehouse_idsAll[d]==JSON.parse(sessionStorage.getItem("orderDetail")).orderBase.parent_warehouse_id ||  sales_manager_idsAll[f]==JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.sales_manager_id || companys_idAll[t]==JSON.parse(sessionStorage.getItem("orderDetail")).orderExt.belong_groupId) {
                            isHas = true;
                            break;
                        }
                    }
                }
            }
            if(!isHas){
                $.Huimodalalert('暂无此订单处理权限！', 2000);
            }else {
                if(isIngReturn){
                    // layer.msg('请求已提交，请勿重复点击！');
                    return false;
                }
                isIngReturn = true;
                getOrderDetai();
                setTimeout(function () {
                    var orderDetail = JSON.parse(sessionStorage.getItem("orderDetail"));
                    var orderState = orderDetail.orderBase.order_status;
                    var url = "orderSuccess_refund2.html";
                    var index = layer.open({
                        type: 2,
                        title: title,
                        content: url
                    });
                    layer.full(index);
                },200)
            }
        }

    }
}
//通过
function adopt(id,order_id,cancle_reason) {
    //订单已关联订货单 qq  root.orderInter.validateWhetherOrdered
    var params={orderId:orderiiid}
    var succCallBack = function (data, status, response) {
        if (data.errorCode == 0) {
            if( orderstatusqq== 20 && data.data.hasOrderedGoods == true){
                var cu = layer.confirm('<span>此订单已关联订货单，是否取消？</span>', {title:'提示',btn: ['确认', '取消']}, function(index){
                    layer.close(cu);
                    adoptfn(id,order_id,cancle_reason)
                    
                },function(){
                    layer.close(cu);
            
                });
            }else{
                adoptfn(id,order_id,cancle_reason) 
            }
        }
    }
    web.doAjax(root.orderInter.validateWhetherOrdered, 'POST', params, succCallBack);
};

function adoptfn(id,order_id,cancle_reason){

    var curInd = layer.confirm(
        '<span>确定通过吗？</span>'+'<br/>', {offset:'230px',title:'提示',btn: ['确定', '取消']}, function(index){
            $.ajax({
                url:root.orderInter.passCancelApply,
                cache: false,  //禁用缓存
                type: "POST",
                dataType:'json',
                contentType: "application/json",
                data: JSON.stringify({
                    "id":id,
                    "order_id":order_id,
                    "login_account":login_accounts,
                    "cancle_reason":cancle_reason,
                }),
                success: function (data) {
                    if(data.code==0){
                        $.Huimodalalert('已通过',2000);
                        getOrderDetai()
                    }else {
                        $.Huimodalalert(data.message,2000);
                    }
                },
                error: function () {
                    $.Huimodalalert('失败！',2000);
                }
            })
            layer.close(curInd);
        },function(){
            layer.close(curInd);
        });
}